﻿@*
    列表集合内容
*@
@using NewLife;
@using NewLife.Cube
@using NewLife.Reflection
@using NewLife.Web;
@using XCode;
@using XCode.Configuration;
@using XCode.Membership;
@using NewLife.Cube.ViewModels;
@{
    var fact = ViewBag.Factory as IEntityFactory;
    var page = ViewBag.Page as Pager;
    var fields = ViewBag.Fields as FieldCollection;
    var fk = fact.Unique;
    var set = ViewBag.PageSetting as PageSetting ?? PageSetting.Global;
}

<div class="card card-flush">
    <div class="card-body">
        <div class="table-responsive dataTables_wrapper dt-bootstrap4">
            <table class="table table-hover table-row-bordered table-row-dashed align-middle gy-4">
                <thead>
                    <tr class="fs-4 text-muted">
                        <th><a href="@Html.Raw(page.GetSortUrl("TreeNodeName"))">节点名</a></th>
                        <th><a href="@Html.Raw(page.GetSortUrl("DisplayName"))">显示名</a></th>
                        <th><a href="@Html.Raw(page.GetSortUrl("Url"))">链接</a></th>
                        <th><a href="@Html.Raw(page.GetSortUrl("Sort"))">排序</a></th>
                        @*<th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Icon"))">图标</a></th>*@
                        <th class="text-center"><a href="@Html.Raw(page.GetSortUrl("Visible"))">可见</a></th>
                        @*<th class="text-center" title="必要。必要的菜单，必须至少有角色拥有这些权限，如果没有则自动授权给系统角色"><a href="@Html.Raw(page.GetSortUrl("Necessary"))">必要</a></th>*@
                        <th title="权限子项。逗号分隔，每个权限子项名值竖线分隔"><a href="@Html.Raw(page.GetSortUrl("Permission"))">权限子项</a></th>
                        @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                        {
                            <th class="text-center">升</th>
                            <th class="text-center">降</th>
                            <th>操作</th>
                        }
                    </tr>
                </thead>
                <tbody>
                    @foreach (var entity in Model)
                    {
                        var p = entity.Parent as IEntityTree;
                        if (p == null)
                        {
                            p = fact.EntityType.GetValue("Root") as IEntityTree;
                        }
                        var id = entity.ID;
                        <tr>
                            <td>
                                @if (entity is Menu menu)
                                {
                                    if (!menu.Icon.IsNullOrEmpty())
                                    {
                                        <i class="far @menu.Icon text-primary"></i>
                                    }
                                    else
                                    {
                                        <i class="far fa-bookmark text-white"></i>
                                    }
                                }
                                @entity.TreeNodeName
                            </td>
                            <td>@entity.DisplayName</td>
                            <td>@entity.Url</td>
                            <td class="text-right">@entity.Sort.ToString("n0")</td>
                            <td class="text-center">
                                @if (entity.Visible)
                                {
                                    <i class="far fa-check fw-bolder text-success"></i>
                                }
                                else
                                {
                                    <i class="far fa-times fw-bolder text-danger"></i>
                                }
                            </td>
                            <td>@entity.Permission</td>
                            @if (this.Has(PermissionFlags.Detail, PermissionFlags.Update, PermissionFlags.Delete))
                            {
                                <td class="text-center">
                                    @if (p != null && p.Childs != null && p.Childs.Count > 0 && entity != p.Childs[0])
                                    {
                                        <a href="@Url.Action("Up", new { id })"><span class="far fa-angle-up fs-2 fw-bolder text-success"></span></a>
                                    }
                                </td>
                                <td class="text-center">
                                    @if (p != null && entity != p.Childs[p.Childs.Count - 1])
                                    {
                                        <a href="@Url.Action("Down", new { id })"><span class="far fa-angle-down fs-2 fw-bolder text-danger"></span></a>
                                    }
                                </td>
                                <td>
                                    @await Html.PartialAsync("_List_Data_Action", (Object)entity)
                                </td>
                            }
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
</div>
